﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTOAuction;
using System.Data.Linq;

namespace DAOAuction
{
    public class DAOPhongHoc
    {
        //Lấy danh sách phòng học
        public List<PHONGHOC> LayDanhSachPhongHoc()
        {
            List<PHONGHOC> lstPhongHoc = new List<PHONGHOC>();
            using (LinqDataContext db = new LinqDataContext(global::DAOAuction.Properties.Settings.Default.QUANLYGIAODUCConnectionString))
            {
                ISingleResult<PHONG_LayDanhSachPhongHocResult> lp = db.PHONG_LayDanhSachPhongHoc();
                foreach (PHONG_LayDanhSachPhongHocResult PHONGHOC in lp)
                {
                    PHONGHOC var1 = new PHONGHOC();
                    var1.MAPHONG = PHONGHOC.MAPHONG;
                    var1.MABOMON = PHONGHOC.MABOMON;
                    var1.TENPHONG = PHONGHOC.TENPHONG;
                    lstPhongHoc.Add(var1);
                }
                try
                {
                    db.SubmitChanges();
                }
                catch (ChangeConflictException)
                {
                    db.ChangeConflicts.ResolveAll(RefreshMode.KeepChanges);
                }
            }
            return lstPhongHoc;
        }

        public PHONGHOC layMaPhongTheoTenPhong(string tenPhong)
        {
            PHONGHOC phonghoctheoma = new PHONGHOC();
            using (LinqDataContext db = new LinqDataContext(global::DAOAuction.Properties.Settings.Default.QUANLYGIAODUCConnectionString))
            {
                ISingleResult<PHONG_LayMaPhongTheoTenPhongResult> lp = db.PHONG_LayMaPhongTheoTenPhong(tenPhong);
                PHONG_LayMaPhongTheoTenPhongResult phong = new PHONG_LayMaPhongTheoTenPhongResult();
                phonghoctheoma.MAPHONG = phong.MAPHONG;
                phonghoctheoma.MABOMON = phong.MABOMON;
                phonghoctheoma.TENPHONG = phong.TENPHONG;
            }
            return phonghoctheoma;
        }
    }
}
